package com.thesis.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {
    private static final long serialVersionUID = 134684324363040701L;
    /**
     * 编码：200成功，500和其它数字为失败
     */
    private Integer code;
    /**
     * 错误信息
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;
    /**
     * 动态数据
     */
    private Map<String,Object> map = new HashMap<>();

    public static  Result success(Object object) {
        Result r = new Result();
        r.data = object;
        r.code = HttpStatus.OK.value();
        return r;
    }
    public static Result success(Integer code,Object object) {
        Result r = new Result();
        r.data = object;
        r.code = code;
        return r;
    }
    public static  Result success(Integer code,Object object,String msg) {
        Result r = new Result();
        r.data = object;
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static  Result success(Integer code,Map<String,Object> map) {
        Result r = new Result();
        r.code = HttpStatus.OK.value();
        r.map = map;
        return r;
    }
    public static  Result success() {
        Result r = new Result();
        r.code = HttpStatus.OK.value();
        return r;
    }

    public static  Result error(String msg) {
        Result r = new Result();
        r.msg = msg;
        r.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        return r;
    }
    public static  Result error(String msg,Integer code) {
        Result r = new Result();
        r.msg = msg;
        r.code = code;
        return r;
    }
    public static  Result error(String msg,Integer code,Object object) {
        Result r = new Result();
        r.msg = msg;
        r.code = code;
        r.data = object;
        return r;
    }
}
